<template>
	<view class="container">
		<block v-if="user!=''">
		<view class="top">
			<view class="tit">签到领取当天所需饲料</view>
			<button size="mini" class="lq-btn" @click="sign(1)" :disabled="user.sign_type1==1">{{user.sign_type1==1?'已签到':'立即签到'}}</button>
		</view>
		<view class="info">
			<view class="tit">日常任务</view>
			<view class="items">
				<view class="item">
					<image src="https://farm-city.oss-cn-hangzhou.aliyuncs.com/static/index/kgg.png" mode="widthFix" class="left-img"></image>
					<view class="right">
						<view class="right-left">
							<view class="right-left-tit">看广告</view>
							<view class="desc">观看广告领取当天所需饲料</view>
						</view>
						<button size="mini" class="btn" :disabled="user.sign_type2==1">{{user.sign_type2==1?'已完成':'去完成'}}</button>
					</view>
				</view>
				<view class="item">
					<image src="https://farm-city.oss-cn-hangzhou.aliyuncs.com/static/index/fxpyq.png" mode="widthFix" class="left-img"></image>
					<view class="right">
						<view class="right-left">
							<view class="right-left-tit">分享朋友圈</view>
							<view class="desc">分享朋友圈领取当天所需饲料</view>
						</view>
						<button size="mini" @click="toQrcode()" class="btn" :disabled="user.sign_type3==1">{{user.sign_type3==1?'已完成':'去完成'}}</button>
					</view>
				</view>
				<view class="item">
					<image src="https://farm-city.oss-cn-hangzhou.aliyuncs.com/static/index/fxwxq.png" mode="widthFix" class="left-img"></image>
					<view class="right">
						<view class="right-left">
							<view class="right-left-tit">分享微信群</view>
							<view class="desc">分享微信群领取当天所需饲料</view>
						</view>
						<button size="mini" @click="toQrcode()" class="btn" :disabled="user.sign_type4==1">{{user.sign_type4==1?'已完成':'去完成'}}</button>
					</view>
				</view>
			</view>
		</view>
		</block>
	</view>
</template>

<script>
	var _this;
	export default {
		data() {
			return {
				user:''
			};
		},
		methods: {
			//获取用户信息
			async get_user_info() {
				// post请求
				const data = await _this.$post('api/UserInfo')
				if (data.code == 200) {
					this.user = data.data.user
				} else {
					this.$u.toast(data.msg)
				}
			},
			async sign(type){
				let params={
					type
				}
				const data = await _this.$post('api/user_qd',params)
				if (data.code == 200) {
					this.$u.toast(data.msg)
					this.user[`sign_type${type}`] = 1
				} else {
					this.$u.toast(data.msg)
				}
			},
			toQrcode(){
				uni.navigateTo({
					url:'/pages/center/qrcode'
				})
			}
		},
		onLoad(e) {
			_this = this;
			_this.get_user_info()
		},
		onShow() {

		},
		components: {}
	}
</script>

<style lang="scss" scoped>
	.container {
		>view{
			background: #fff;
			border-radius: 20rpx;
		}
		.top{
			padding: 30rpx;
			.tit{
				font-weight: 500;
				font-size: 32rpx;
			}
			.lq-btn{
				display: block;
				margin: 30rpx auto 0;
				background: $theme-color;
				color: #fff;
				width: 300rpx;
				height: 100rpx;
				line-height: 100rpx;
				font-size: 30rpx;
				border-radius: 20rpx;
				&[disabled]{
					background: rgba($theme-color, 0.5);
				}
			}
		}
		.info{
			padding:20rpx 30rpx;
			margin-top: 20rpx;
			.tit{
				font-weight: 500;
				font-size: 32rpx;
			}
			.items{
				margin-top: 20rpx;
				.item{
					@include flex-box(row);
					&:not(:last-child){
						margin-bottom: 20rpx;
					}
					.left-img{
						width: 90rpx;
						margin-right: 15rpx;
					}
					.right{
						flex: 1;
						@include flex-box(row,space-between,center);
						.right-left{
							.right-left-tit{
								font-size: 30rpx;
								font-weight: 500;
							}
							.desc{
								color: $color-919191;
								font-size: 24rpx;
							}
						}
						.btn{
							background: $theme-color;
							color: #fff;
							width: 140rpx;
							height: 48rpx;
							line-height: 48rpx;
							border-radius: 30rpx;
							padding: 0;
							&[disabled]{
								background: rgba($theme-color, 0.5);
							}
						}
					}
				}
			}
		}
	}
</style>
